package com.yhc.config;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;


/**
 * @author yhc
 * @create 2021-07-12-18:51
 */
@org.springframework.context.annotation.Configuration
@ComponentScan("com.yhc")
@PropertySource("classpath:jdbc.properties")
public class SpringConfiguration {
    @Value("${jdbc.driver}")
    String driver;
    @Value("${jdbc.url}")
    String url;
    @Value("${jdbc.user}")
    String user;
    @Value("${jdbc.password}")
    String password;


    @Bean("dataSource")
    public DataSource getDataSource(){
        DruidDataSource druidDataSource =new DruidDataSource();
        druidDataSource.setDriverClassName("com.mysql.jdbc.Driver");
        druidDataSource.setUrl("jdbc:mysql://localhost:3306/book");
        druidDataSource.setUsername("root");
        druidDataSource.setPassword("chenchen");
        return druidDataSource;
//        System.out.println(druidDataSource.getConnection());
    }
}
